package com.javasm.crm.service.marketingActivity.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.javasm.crm.domin.entity.marketingActivity.Marketing;
import com.javasm.crm.domin.entity.marketingActivity.clinetClaim.MarketingFindClaim;
import com.javasm.crm.mapper.marketingActivity.MarketingMapper;
import com.javasm.crm.service.marketingActivity.MarketingService;
import com.javasm.crm.utils.page.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author llyp
 * @since 2021-07-12
 */
@Service
public class MarketingServiceImpl extends ServiceImpl<MarketingMapper, Marketing> implements MarketingService {

    @Autowired
    private MarketingMapper marketingMapper;

    @Override
    public PageResult<Marketing> ConditionFindPage(MarketingFindClaim mfc) {

        System.out.println("页数信息====》"+mfc.getCurrent());
        Page page = new Page<>(mfc.getCurrent(),mfc.getSize());

        QueryWrapper queryWrapper= new QueryWrapper();

        if (mfc.getMarketingId()!=null){
            queryWrapper.eq("marketing_id",mfc.getMarketingId());
        }
        if (StringUtils.hasLength(mfc.getMarketingName())){
            queryWrapper.like("marketing_name",mfc.getMarketingName());
        }
        if (mfc.getMarketingDate()!=null){
            queryWrapper.eq("marketing_date",mfc.getMarketingDate());
        }
        if (mfc.getMarketingApprovalstatus()!=null){
            queryWrapper.eq("marketing_approvalstatus",mfc.getMarketingApprovalstatus());
        }
        if (mfc.getRewardWay()!=null){
            queryWrapper.eq("RewardWay",mfc.getRewardWay());
        }

        System.out.println("页数信息");
        Page<Marketing> marketingPage = marketingMapper.selectPage(page, queryWrapper);

        List<Marketing> marketings =marketingPage.getRecords();

        long total = marketingPage.getTotal();
        return new PageResult<Marketing>(total,marketings);

    }
}
